package com.cmict.data.infra.dal.mysql.rdbtabledraft;

import java.util.*;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.cmict.data.framework.common.pojo.PageResult;
import com.cmict.data.framework.mybatis.core.query.LambdaQueryWrapperX;
import com.cmict.data.framework.mybatis.core.mapper.BaseMapperX;
import com.cmict.data.infra.dal.dataobject.rdbcolumn.RdbColumnDO;
import com.cmict.data.infra.dal.dataobject.rdbtabledraft.RdbTableDraftDO;
import org.apache.ibatis.annotations.Mapper;
import com.cmict.data.infra.controller.admin.rdbtabledraft.vo.*;

/**
 * 草稿 Mapper
 *
 * @author awesome1114
 */
@Mapper
public interface RdbTableDraftMapper extends BaseMapperX<RdbTableDraftDO> {

    default PageResult<RdbTableDraftDO> selectPage(RdbTableDraftPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<RdbTableDraftDO>()
                .likeIfPresent(RdbTableDraftDO::getTableName, reqVO.getTableName())
                .eqIfPresent(RdbTableDraftDO::getTableComment, reqVO.getTableComment())
                .eqIfPresent(RdbTableDraftDO::getContent, reqVO.getContent())
                .betweenIfPresent(RdbTableDraftDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(RdbTableDraftDO::getId));
    }

    default List<RdbTableDraftDO> selectList(RdbTableDraftExportReqVO reqVO) {
        return selectList(new LambdaQueryWrapperX<RdbTableDraftDO>()
                .likeIfPresent(RdbTableDraftDO::getTableName, reqVO.getTableName())
                .eqIfPresent(RdbTableDraftDO::getTableComment, reqVO.getTableComment())
                .eqIfPresent(RdbTableDraftDO::getContent, reqVO.getContent())
                .betweenIfPresent(RdbTableDraftDO::getCreateTime, reqVO.getBeginCreateTime(), reqVO.getEndCreateTime())
                .orderByDesc(RdbTableDraftDO::getId));
    }

   default List<RdbTableDraftDO> selectListByKeyword(String keyword){
        QueryWrapper<RdbTableDraftDO> queryWrapper=new QueryWrapper<>();
        if(keyword != null){
            queryWrapper.lambda().and(qw -> qw.like(RdbTableDraftDO::getTableName, keyword)
                    .or().like(RdbTableDraftDO::getTableComment, keyword));
        }
        queryWrapper.lambda().orderByDesc(RdbTableDraftDO::getCreateTime);
      return   selectList(queryWrapper);
    }
}
